<!-- 
   图文结构封装组件
  -->
<template>
  <div>
    <el-table :data="tableData" style="width: 100%" size="mini" border>
      <el-table-column type="index" width="50" label="序号" align="center">
      </el-table-column>
      <el-table-column
        label="委托项目"
        prop="projectTypeName"
        align="center"
        width="220px;"
      >
        <template slot-scope="scope">
          <div>
            <el-select
              v-model="scope.row.projectTypeName"
              placeholder="请选择"
              style="width:200px;"
              size="mini"
              filterable
              allow-create
            >
              <el-option
                v-for="(data, index) in applyServiceList"
                :key="index"
                :label="data.settingCode"
                :value="data.settingCode"
              >
              </el-option>
            </el-select>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="项目名称"
        prop="projectName"
        align="center"
        width="150px;"
      >
        <template slot-scope="scope">
          <div>
            <el-input
              type="textarea"
              v-model="scope.row.projectName"
              placeholder="请输入内容"
              style="width:130px;"
              maxlength="500"
              show-word-limit
              resize="none"
              :autosize="{ minRows: 3 }"
            ></el-input>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="案卷号"
        prop="orderNumber"
        align="center"
        width="150px;"
      >
        <template slot-scope="scope">
          <div>
            <el-input
              v-model="scope.row.orderNumber"
              style="width:130px;"
              disabled
            ></el-input>
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="备注说明"
        prop="projectDesc"
        align="center"
        width="150px;"
      >
        <template slot-scope="scope">
          <div>
            <el-input
              type="textarea"
              v-model="scope.row.projectDesc"
              placeholder="请输入内容"
              style="width:130px;"
              maxlength="500"
              show-word-limit
              resize="none"
              :autosize="{ minRows: 3 }"
            ></el-input>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="委托费（元）" align="center">
        <template slot-scope="scope">
          <div>
            <el-input
              v-model="scope.row.commissionFee"
              style="width:80px;"
              size="mini"
              maxlength="50"
              @blur="onFeeBlur"
              oninput="value=value.replace(/[^0-9]/g,'')"
            ></el-input>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="代理费（元）" align="center">
        <template slot-scope="scope">
          <div>
            <el-input
              v-model="scope.row.agencyFee"
              style="width:80px;"
              size="mini"
              maxlength="50"
              @blur="onFeeBlur"
            ></el-input>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="申请费（元）" align="center">
        <template slot-scope="scope">
          <div>
            <el-input
              v-model="scope.row.applyFee"
              style="width:80px;"
              size="mini"
              maxlength="50"
              @blur="onFeeBlur"
            ></el-input>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="其他费用（元）" prop="legalDesc3" align="center">
        <template slot-scope="scope">
          <div>
            <el-input
              v-model="scope.row.otherFee"
              style="width:80px;"
              size="mini"
              maxlength="50"
              @blur="onFeeBlur"
            ></el-input>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="删除" align="center" width="80px;">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            plain
            style="margin: 5px"
            @click="del(scope.$index)"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="add-text">
      <span @click="addLine"><i class="el-icon-plus"></i>点击添加</span>
    </div>
  </div>
</template>
<script>
import {
  applyCategoryListApi
} from "@s/api";
export default {
  name: "filesList",
  props: ["tableData"],
  data() {
    return {
      applyServiceList: [],
      url: process.env.VUE_APP_URL + "/sys/oss/upload",
      hideUpload: false,
      imgIndex: 0
    };
  },
  components: {},
  mounted() {
       this.applyCategoryListHandle()
  },
  
  methods: {
    onFeeBlur() {
      let total = 0;
      for (var i = 0; i < this.tableData.length; i++) {
        if (
          this.tableData[i].commissionFee &&
          this.tableData[i].commissionFee != ""
        ) {
          total = total + parseInt(this.tableData[i].commissionFee);
        }
        if (this.tableData[i].applyFee && this.tableData[i].applyFee != "") {
          total = total + parseInt(this.tableData[i].applyFee);
        }
        if (this.tableData[i].agencyFee && this.tableData[i].agencyFee != "") {
          total = total + parseInt(this.tableData[i].agencyFee);
        }
        if (this.tableData[i].otherFee && this.tableData[i].otherFee != "") {
          total = total + parseInt(this.tableData[i].otherFee);
        }
      }
      this.$emit("handleChangeFee", total);
    },
    del(value) {
      this.tableData.splice(value, 1);
      this.onFeeBlur();
      this.$emit("handleTableDate", this.tableData);
    },
    addLine() {
      //添加行数
      var newValue = {
        id: undefined,
        orderNumber: undefined,
        projectTypeName: "",
        projectName: "",
        projectDesc: "",
        commissionFee: "",
        agencyFee: "",
        applyFee: "",
        otherFee: ""
      };
      //添加新的行数
      this.tableData.push(newValue);
      this.$emit("handleTableDate", this.tableData);
    },
    applyCategoryListHandle() {
      applyCategoryListApi().then(res => {
        res.map(item => {
          this.applyServiceList = this.applyServiceList.concat(item.sons);
        })
      })
    },
  }
};
</script>
<style scoped lang="scss">
.sort {
  cursor: pointer;
  color: #409eff;
}
.sort:hover {
  color: #027cfb;
}
.add-text {
  text-align: center;
  span {
    cursor: pointer;
    color: #027cfb;
  }
}
</style>
